package com.chauncy.DMS.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import sun.net.www.http.Hurryable;
import util.List2Json1.List2Json1;

import com.chauncy.DMS.bean.DormInfoBean;
import com.chauncy.DMS.bean.ManagerInfoBean;
import com.chauncy.DMS.dao.ManagerDaoImplement;

public class SelectDormPeopleServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		List<ManagerInfoBean> list = (List)request.getSession().getAttribute("managerInfoList");
		String buildings = list.get(0).getManager_buildings();
		System.out.println("buildings"+list);
		ManagerDaoImplement daoImplement = new ManagerDaoImplement();
		List<DormInfoBean> dormInfoList = new ArrayList<DormInfoBean>();	
		int limit = 0;
		int page = 0;
		try {
			//获取 当前页码page  以及当前页显示条目数limit
			 limit = Integer.parseInt(request.getParameter("limit"));
			 page = Integer.parseInt(request.getParameter("page"));
			// System.out.println(page+"page/////limit"+limit);
			 //分页查询
			dormInfoList = daoImplement.selectDormPeople(buildings,page,limit);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONObject array = 	List2Json1.listToJson(dormInfoList,buildings);
		//System.out.println("SelectDormPeopleServlet JSONArray size:"+array.size());
		//System.out.println(array);
		if(array.size() > 0 && array != null){		
			request.setAttribute("dormInfoList", array);
			response.getWriter().print(array);
		}
	}
}
